package com.cms.edm.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.cms.edm.entity.vo.ResultOptionInVo;
import com.cms.edm.entity.vo.ResultOptionOutVo;
import com.cms.edm.entity.vo.ResultVo;
import com.cms.edm.to.ClassTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.cms.edm.entity.ResultEntity;
import com.cms.edm.service.ResultService;
import com.cms.common.utils.PageUtils;
import com.cms.common.utils.R;



/**
 * 
 *
 * @author weixiaochun
 * @email xiaochun0121@163.com
 * @date 2022-03-15 10:48:10
 */
@RestController
@RequestMapping("edm/result")
public class ResultController {

    @Autowired
    private ResultService resultService;


    /**
     * 根据教师ID查询教授的班级信息
     */
    @RequestMapping("/classInfoByTeacherId/{teacherId}")
    //@RequiresPermissions("edm:result:list")
    public R classInfoByTeacherId(@PathVariable("teacherId") Long teacherId){
        List<ClassTo> classTos = resultService.classInfoByTeacherId(teacherId);

        return R.ok().put("classTos", classTos);
    }

    /**
     * 查询指定教师下的所有课程成绩
     */
    @RequestMapping("/resultByTeacherId")
    //@RequiresPermissions("edm:result:list")
    public R resultByTeacherId(@RequestBody ResultOptionInVo option){
        List<ResultOptionOutVo> outVos = resultService.resultByTeacherId(option);

        return R.ok().put("outVos", outVos);
    }

    /**
     * 根据模板设置成绩
     */
    @GetMapping("/selectAllCourseByStudentId/{studentId}")
    //@RequiresPermissions("edm:result:list")
    public R selectAllCourseByStudentId(@PathVariable Long studentId){
        List<ResultVo> resultVos = resultService.selectAllCourseByStudentId(studentId);
        return R.ok().put("resultVos", resultVos);
    }

    /**
     * 根据模板设置成绩
     */
    @PostMapping("/setResultByTemplate")
    //@RequiresPermissions("edm:result:list")
    public R setResultByTemplate(@RequestParam Long templateId, @RequestParam Long classId){
        resultService.setResultByTemplate(templateId, classId);
        return R.ok();
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("edm:result:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = resultService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("edm:result:info")
    public R info(@PathVariable("id") Long id){
		ResultEntity result = resultService.getById(id);

        return R.ok().put("result", result);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("edm:result:save")
    public R save(@RequestBody ResultEntity result){
		resultService.save(result);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("edm:result:update")
    public R update(@RequestBody ResultEntity result){
		resultService.updateById(result);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("edm:result:delete")
    public R delete(@RequestBody Long[] ids){
		resultService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
